package com.aijk.web.admin.controller.sys;

import com.aijk.commons.lang.utils.StringUtil;
import com.aijk.commons.utils.Utils;
import com.aijk.ehm.api.SysFeedbackApi;
import com.aijk.ehm.model.SysFeedback;
import com.aijk.ehm.model.qo.SysFeedbackQo;
import com.aijk.web.admin.RetMsg;
import com.aijk.web.admin.utils.DataTableUtil;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;


@Controller
@RequestMapping(value = "/admin/sys/feedback")
public class SysFeedbackController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SysFeedbackApi sysFeedbackApi;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list_view() {
        return "sys/feedback_list";
    }

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public RetMsg list(@RequestParam HashMap skey,@RequestParam(value = "draw", defaultValue = "1") Integer draw) {
        Long iTotalRecords;
        DataTableUtil.FormatOptions(skey);
        if (Utils.isNotEmpty(skey.get("orderbyclause"))) {
            skey.put("orderbyclause", StringUtil.toUnderlineCase(Utils.toString(skey.get("orderbyclause"))));
        }
        SysFeedbackQo qo = DataTableUtil.fillQo(skey, SysFeedbackQo.class);
        draw += 1;
        PageInfo<SysFeedback> sysfeedbackList = sysFeedbackApi.page(qo);

        iTotalRecords =sysfeedbackList.getTotal();
        RetMsg regMsg = new RetMsg();

        regMsg.put("data", sysfeedbackList.getList());
        regMsg.put("draw", draw);
        regMsg.put("recordsTotal", iTotalRecords);
        regMsg.put("recordsFiltered", iTotalRecords);

        return regMsg;
    }

}
